package com.bingqing.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.bingqing.common.AutoLog;
import com.bingqing.common.Result;
import com.bingqing.entity.Book;
import com.bingqing.entity.Hotel;
import com.bingqing.entity.Params;
import com.bingqing.entity.Type;
import com.bingqing.exception.CustomException;
import com.bingqing.service.HotelService;
import com.bingqing.service.TypeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: TypeController
 * Package: com.bingqing.controller
 * Description:
 *
 * @Author liuyujie
 * @Create 2024-03-10 9:24
 * @Version 1.0
 */
@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Resource
    HotelService hotelService;

    //分页查询
    @GetMapping("/search")
    public Result findBySearch(Params params) {
        PageInfo<Hotel> info = hotelService.findBySearch(params);
        return Result.success(info);
    }


    //保存
    @PostMapping("/save")
    @AutoLog("编辑酒店")
    public Result save(@RequestBody Hotel hotel) {
        if (hotel.getId() == null) {
            hotelService.add(hotel);
        } else {
            hotelService.update(hotel);
        }
        return Result.success();
    }
    @PostMapping("/add")
    @AutoLog("新增酒店")
    public Result add(@RequestBody Hotel hotel){
        hotelService.add(hotel);
        return Result.success();
    }
    @PostMapping("/edit")
    @AutoLog("编辑酒店")
    public Result edit(@RequestBody Hotel hotel){
        hotelService.update(hotel);
        return Result.success();
    }
    //删除
    @AutoLog("删除酒店")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        hotelService.deleteById(id);
        return Result.success();
    }

}
